package View;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.io.Serializable;
import java.awt.Font;


/** this class create the GUI to first window in order to manage the login to the system **/
public class LoginView extends JFrame implements Serializable  {
	
	private static final long serialVersionUID = 42L; 
	/** Required fields and buttons **/
	 JLabel UserNameButton;
	 JLabel PasswordButton;
	 JButton LoginButton;
	 JButton CancelButton;
	 JPasswordField passwordField;
	 JTextField UserNameField;
	 
	
   /** default and only constructor **/
	public LoginView()
	{
   	    this.setLocationRelativeTo(null); 
		this.setResizable(false);
		this.setBounds(450, 200,345,266);
		this.setTitle("Welcome To CCRM System  :Login Window ");
		this.showWindow();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		getContentPane().setLayout(null);
		
		UserNameButton = new JLabel("User Name");
		UserNameButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		UserNameButton.setBounds(10, 24, 102, 28);
		getContentPane().add(UserNameButton);
		
		PasswordButton = new JLabel("Password");
		PasswordButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		PasswordButton.setBounds(10, 63, 102, 21);
		getContentPane().add(PasswordButton);
		
		LoginButton = new JButton("Login");
		LoginButton.setFont(new Font("Tahoma", Font.BOLD, 13));
		LoginButton.setBounds(90, 129, 158, 28);
		getContentPane().add(LoginButton);
		
		CancelButton = new JButton("Cancel");
		CancelButton.setFont(new Font("Tahoma", Font.BOLD, 12));
		CancelButton.setBounds(90, 168, 158, 28);
		getContentPane().add(CancelButton);
		
		
		passwordField = new JPasswordField();
		passwordField.setBounds(122, 63, 126, 20);
		getContentPane().add(passwordField);
		
		UserNameField = new JTextField();
		UserNameField.setBounds(122, 28, 126, 20);
		getContentPane().add(UserNameField);
		UserNameField.setColumns(10);
	}
	
	
	
	/** show and hide window functions **/
	public void showWindow(){
		setVisible(true);
	}
	public void hideWindow(){
		setVisible(false);
	}
	

	/**
	 * 
	 * @return text fields Username
	 */
	public String getUsername(){
		return UserNameField.getText();
	}
	
	/**
	 * 
	 * @return field Password
	 */
	public String getPassword(){
		return String.valueOf(passwordField.getPassword());
	}
	
	/**
	 *  clear the field username
	 */
	public void clearUsername(){
		UserNameField.setText("");
	}
	/**
	 *  clear the field password
	 */
	public void clearPassword(){
		passwordField.setText("");
	}
	
	/** get buttons functions **/
	public  JButton getLoginButton() {
		return LoginButton;
	}
	public  JButton getCancelButton() {
		return CancelButton;
	}
	
	
	/**
	 * add listeners to login and cancel buttons
	 * @param actionListener
	 */
	public void addLoginListeners(ActionListener actionListener)
	{
		LoginButton.addActionListener(actionListener);
		CancelButton.addActionListener(actionListener);
	}
}
